package com.example.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.ZonedDateTime;

/**
 * 本类用来演示:跟配置文件(yml)中的配置,并不冲突,yml文件中的也能正常使用
 *
 * @Author 胡英俊
 * @Date 2022/7/21 23:33
 */
@Configuration
public class gateWayConfig {
//    仿照官网写
    @Bean
    public RouteLocator customRouteLocator(RouteLocatorBuilder builder) {
        return builder.routes()
                .route("path_route_id", r -> r.path("/variety")
                        .uri("https://www.bilibili.com/"))
//                当uri后面拼接了,就不会再次拼接了,不会吧path在拼接到uri上面
//                .route("path_route_id", r -> r.path("/variety")
//                        .uri("https://www.bilibili.com/variety"))
                .route("host_route_id", r -> r.host("v/dance")
                        .uri("https://www.bilibili.com/"))
//                .route("host_route", r -> r.host("*.myhost.org")
//                        .uri("https://www.bilibili.com/"))

                .build();
    }

    public static void main(String[] args) {
        ZonedDateTime now = ZonedDateTime.now();
        System.out.println(now);
//        2022-07-23T23:30:13.910+08:00[Asia/Shanghai]
    }
}
